﻿/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework
 * Version 2.10
 * 
 * CNR Object Base Class
 *      Provides an abstract base definition for all CNR framework objects.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
using System;
using Adaptive.Foundation;

namespace Adaptive.Foundation.Network.Cnr
{
    /// <summary>
    /// Provides an abstract base definition for all CNR framework objects.
    /// </summary>
    public abstract class CnrObjectBase : AiObjectBase
    {
        /*--------------------------------------------------------------------------------
         * Public Event Definitions
         *------------------------------------------------------------------------------*/
        #region Public Event Definitions
        /// <summary>
        /// Occurs when a protocol error is encountered.
        /// </summary>
        public event CnrErrorEventHandler ProtocolError;
        /// <summary>
        /// Occurs when a validation error is encountered.
        /// </summary>
        public event CnrValidationErrorEventHandler ValidationError;
        /// <summary>
        /// Occurs when an exception is caught during a rendering operation.
        /// </summary>
        public event ExceptionEventHandler RenderingException;
        /// <summary>
        /// Occurs when an exception is caught during a parsing operation.
        /// </summary>
        public event ExceptionEventHandler ParsingException;
        /// <summary>
        /// Occurs when an exception is caught during an implementation operation.
        /// </summary>
        public event ExceptionEventHandler ImplementationException;
        #endregion

        /*--------------------------------------------------------------------------------
         * Constructor / Dispose / Destructor Methods
         *------------------------------------------------------------------------------*/
        #region Constructor / Dispose / Destructor Methods
        /// <summary>
        /// Initializes a new instance of the class.
        /// </summary>
        /// <remarks>
        /// This is the default constructor.
        /// </remarks>
        protected CnrObjectBase()
            : base()
        {
        }
        #endregion

        /*--------------------------------------------------------------------------------
         * Protected Methods / Event Methods
         *------------------------------------------------------------------------------*/
        #region Protected Methods / Event Methods
        /// <summary>
        /// Raises the <see cref="ProtocolError"/> event.
        /// </summary>
        /// <param name="e">
        /// A <see cref="CnrErrorEventArgs"/> event arguments instance containing
        /// the error.
        /// </param>
        protected virtual void OnProtocolError(CnrErrorEventArgs e)
        {
            if (ProtocolError != null)
                ProtocolError(this, e);
        }
        /// <summary>
        /// Raises the <see cref="ValidationError"/> event.
        /// </summary>
        /// <param name="e">
        /// A <see cref="CnrValidationErrorEventArgs"/> event arguments instance containing
        /// the error.
        /// </param>
        protected virtual void OnValidationError(CnrValidationErrorEventArgs e)
        {
            if (ValidationError != null)
                ValidationError(this, e);
        }
        /// <summary>
        /// Raises the <see cref="RenderingException"/> event.
        /// </summary>
        /// <param name="e">
        /// An <see cref="ExceptionEventArgs"/> event arguments instance
        /// containing the exception.
        /// </param>
        protected virtual void OnRenderingException(ExceptionEventArgs e)
        {
            if (RenderingException != null)
                RenderingException(this, e);
        }
        /// <summary>
        /// Raises the <see cref="ParsingException"/> event.
        /// </summary>
        /// <param name="e">
        /// An <see cref="ExceptionEventArgs"/> event arguments instance
        /// containing the exception.
        /// </param>
        protected virtual void OnParsingException(ExceptionEventArgs e)
        {
            if (ParsingException != null)
                ParsingException(this, e);
        }
        /// <summary>
        /// Raises the <see cref="ImplementationException"/> event.
        /// </summary>
        /// <param name="e">
        /// An <see cref="ExceptionEventArgs"/> event arguments instance
        /// containing the exception.
        /// </param>
        protected virtual void OnImplementationException(ExceptionEventArgs e)
        {
            if (ImplementationException != null)
                ImplementationException(this, e);
        }
        #endregion
    }
}